package exam.controller;

import exam.bean.PatentType;
import exam.service.IPatentTypeService;
import exam.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/PatentType")
public class PatentTypeController {
    @Autowired
    IPatentTypeService patentTypeService;

    @ResponseBody
    @GetMapping("/PatentTypeSelect")
    @PreAuthorize("hasAuthority('sys:sysParam:patentType:list')")
    public Msg patentTypeSelect(){
        return Msg.success().add("patentType",patentTypeService.getPatentTypeList());
    }

    @ResponseBody
    @PostMapping("/PatentTypeInsert")
    @PreAuthorize("hasAuthority('sys:sysParam:patentType:add')")
    public Msg patentTypeInsert(@RequestBody PatentType patentType){
        int res = patentTypeService.insertInfo(patentType);
        return res > 0 ? Msg.success().setMessage("添加成功") : Msg.fail().setMessage("添加失败");
    }

    @ResponseBody
    @PostMapping("/PatentTypeUpdate")
    @PreAuthorize("hasAuthority('sys:sysParam:patentType:update')")
    public Msg patentTypeUpdate(@RequestBody PatentType patentType){
        int res = patentTypeService.updateInfo(patentType);
        return res > 0 ? Msg.success().setMessage("修改成功") : Msg.fail().setMessage("修改失败");
    }

    @ResponseBody
    @GetMapping("/PatentTypeDelete")
    @PreAuthorize("hasAuthority('sys:sysParam:patentType:delete')")
    public Msg patentTypeDelete(@RequestParam(value = "id") int id){
        int res = patentTypeService.deleteInfo(id);
        return res > 0 ? Msg.success().setMessage("删除成功") : Msg.fail().setMessage("删除失败");
    }

    @ResponseBody
    @GetMapping("/PatentTypeDetail")
    @PreAuthorize("hasAuthority('sys:sysParam:patentType:update')")
    public Msg patentTypeDetail(@RequestParam(value = "id") int id){
        Map<String,Object> queryMap =new HashMap<String,Object>();
        queryMap.put("id",id);
        return Msg.success().add("patentTypeInfo",patentTypeService.selectInfoSingle(queryMap));
    }


}
